<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../vue.js"></script>
  </head>
  <body>
    <p>局部组件注册</p>
    <div id="root">
      <my-component></my-component>
    </div>
    <script>
      var col = {
        template: "<div>这是局部组件</div>",
      };
      new Vue({
        el: "#root",
        components: {
          myComponent: col,
        },
      });
    </script>
    <hr />
    <div id="app">
      <p>{{title}}</p>
      <my-component-a></my-component-a>
    </div>
    <template id="temp1">
      <div>
        <p>{{title}}</p>
      </div>
    </template>
    <script>
      Vue.component("my-component-a", {
        template: "#temp1",
        data() {
          return {
            title: "我是组件内部的title",
          };
        },
      });
      new Vue({
        el: "#app",
        data() {
          return {
            title: "我是组件外部的div",
          };
        },
      });
    </script>
  </body>
</html>
